package mt.dummy;

import mt.Order;
import mt.comm.ClientSideMessage;
import mt.comm.ClientSideMessage.Type;


/**
 * 
 * @author Grupo45
 *
 */
public class ClientMessage implements ClientSideMessage {
	
	private Order order;
	private String error;
	private Type type;
	
	
	/**
	 * The message contains a new order or an update to an existing order
	 * @param order
	 */
	public ClientMessage(Order order) {
		type=Type.ORDER;
		this.order=order;
	}

	/**
	 * An error occurred
	 * @param error
	 */
	public ClientMessage(String error){
		type=Type.ERROR;
		this.error=error;
	}
	
	/**
	 * Gets the type of the message
	 * 
	 * @return type of the message
	 */
	@Override
	public Type getType() {
		return type;
	}

	/**
	 * If message type is {@link Type#ORDER}, the method is a getter for the order
	 * 
	 * @return the {@link Order} in the message
	 */
	@Override
	public Order getOrder() {
		return order;
	}

	/**
	 * If the type of the message is {@link Type#ERROR}, the method returns the error message. 
	 *
	 * @return error message.
	 */
	@Override
	public String getError() {
		return error;
	}

}
